package logic

import (
	"context"
	"teatch/teacherrpc/teacherrpc"

	"teatch/api/internal/svc"
	"teatch/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type CourseAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewCourseAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CourseAddLogic {
	return &CourseAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *CourseAddLogic) CourseAdd(req *types.CourseAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	add, err := l.svcCtx.TeacherRpc.CourseAdd(l.ctx, &teacherrpc.CourseAddRequest{
		TeachersId: req.TeachersId,
		Title:      req.Title,
		Types:      req.Types,
		Content:    req.Content,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    500,
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Message: "课程添加成功",
		Code:    200,
		Data:    add,
	}, nil

}
